<template>
	<view class="mt66 mh32">
		<view class="van" style="margin-top: 88rpx;">
			<view style="margin-top: 20rpx;" @click="back"><u-icon size="44rpx" name="arrow-left"></u-icon></view>
			<!-- 出现答题后按钮变成蓝色 -->
			<view @click="$u.throttle(present, 500)"><text class="btn ">{{ page=='index'? "发布":"回答" }}</text></view>
		</view>
		<slot name='title-msg'></slot>
		<view class="mt18 " style="text-indent:38rpx;">
			<textarea
				style="line-height: 66rpx;"
				class="huiFu"
				name=""
				id=""
				v-model="content"
				maxlength="400"
				rows="15"
				placeholder="添加问题描述"
				οnchange="this.value=this.value.substring(0, 200)"
				οnkeydοwn="this.value=this.value.substring(0, 200)"
				οnkeyup="this.value=this.value.substring(0, 200)"
			></textarea>
		</view>
		<slot name='foot-msg'></slot>
	</view>
</template>

<script>
import { circlePub , comment  } from '@/api/me.js'
export default{
	props:{
		page:{
			type:String,
			default:''
		},
		id:{
			type:String,
			default:'1'
		}
	},
	data () {
		return {
			content:'',//文本域
		}
	},
	methods:{
		//点击发布 或 回答
		pubpresent(){
			if( this.page == 'index' ){
				circlePub({
					content:this.content,
					type:2,
				}).then(res=>{
					console.log( res );
				})
			}else{
				comment({
					id:this.id,
					content:this.content
				}).then(res=>{
					console.log( res );
				})
			}
			
		},
		present(){
			uni.$u.debounce(this.pubpresent, 500)
		},
		//返回上一页
		back(){
			if( this.page == 'index' ){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
			uni.navigateBack();
			
		}
		
	}
}
</script>

<style>
.van {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.btn {
	display: block;
	width: 106rpx;
	height: 48rpx;
	text-align: center;
	line-height: 45rpx;
	font-size: 32rpx;
	background: linear-gradient(to right, #0f9dec, #105cf0);
	color: #fff;
	border: 1rpx solid #f1f1f1;
	border-radius: 60rpx;
}
.wenti {
	padding-bottom: 36rpx;
	border-bottom: 1rpx solid #c4c4c4;
}
.huiFu {
	width: 686rpx;
	height: 616rpx;
	border: 1rpx solid #000000;
}
</style>
